package threadcoreknowledge.sync;

public class SynchronizedClassCodeClass5 implements Runnable {
    private static SynchronizedClassCodeClass5 instance1 = new SynchronizedClassCodeClass5();
    private static SynchronizedClassCodeClass5 instance2 = new SynchronizedClassCodeClass5();
    final Object lock1 = new Object();
    final Object lock2 = new Object();

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(instance1);
        Thread t2 = new Thread(instance2);
        t1.start();
        t2.start();


        while (t1.isAlive() || t2.isAlive()) {

        }
        System.out.println("finished");
    }

    @Override
    public void run() {
        synchronized (SynchronizedClassCodeClass5.class) {
            System.out.println(Thread.currentThread().getName());
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + " 运行结束");
        }
    }
}
